package com.zy.configs;

import com.zy.utils.DataCenterIdAssigner;
import com.zy.utils.SnowFlakeIdGenerator;
import com.zy.utils.WorkerIdAssigner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: shopping153_cloud
 * @description: 雪花算法配置类
 * @author: zy
 * @create: 2025-08-20 14:10
 */
@Configuration
public class SnowflakeConfig {

    @Autowired
    private DataCenterIdAssigner dataCenterIdAssigner;
    @Autowired
    private WorkerIdAssigner workerIdAssigner;


    /**
     * 创建雪花算法id生成器对象
     * @return
     */
    @Bean
    public SnowFlakeIdGenerator snowflakeIdGenerator(){
        long dataCenterId = dataCenterIdAssigner.getDataCenterId();
        long workerId = workerIdAssigner.getWorkerId();
        return new SnowFlakeIdGenerator(dataCenterId, workerId);  //  0L, 1L
    }
}
